package com.lhy.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

/**
 * @author 汪
 */
public class CustomObjectMapper extends ObjectMapper {
    public CustomObjectMapper(){
        super();
        configure(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS,false);
        setTimeZone(TimeZone.getTimeZone("GTM+8"));
        setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

        configure(SerializationFeature.WRITE_NULL_MAP_VALUES,false);
        setSerializationInclusion(JsonInclude.Include.NON_NULL);
        getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
        configure(SerializationFeature.WRITE_ENUMS_USING_TO_STRING,true);
    }
}
